import { reqAddCart, reqDetailList } from "@/api"

export default {
    namespaced: true,
    actions: {
        getDetailList({commit}, goodId) {
            reqDetailList(goodId).then((resp)=> {
                if (resp.code == 200) {
                    commit('GETDETAILLIST', resp.data);
                }
            }, (err)=> {
                return Promise.reject(err);
            })
        },
        async addCart({commit}, {goodId, skuNum}) {
            let result = await reqAddCart(goodId, skuNum);
            if (result.code == 200) {
                return 'ok'
            }else Promise.reject('fail');
        }
    },
    mutations: {
        GETDETAILLIST(state, data) {
            state.detailList = data;
        },
        ADDCART() {
            return 'ok';
        },
    },
    state: {
        detailList:{},
    },
    getters: {
        categoryView(state){
            return state.detailList.categoryView || {};
        },
        skuInfo(state){
            return state.detailList.skuInfo || {};
        },
        spuSaleAttrList(state){
            return state.detailList.spuSaleAttrList || [];
        },
    }
}